package br.com.lambdacore.validator.impl;

import br.com.lambdacore.validator.Validator;

public class ClassValidator extends Validator<Class<?>> {

	protected ClassValidator(Class<?> clazz) {
		super(clazz);
	}

	public boolean instanceOf(Class<?> other) {
		Class<?> clazz = this.getObject();

		while (is(clazz).notNil()) {
			if (is(clazz).notEqualThan(other)) {
				clazz = clazz.getSuperclass();
			} else {
				return true;
			}
		}

		return false;
	}

	public boolean notInstanceOf(Class<?> other) {
		return !this.instanceOf(other);
	}

	public static ClassValidator is(Class<?> clazz) {
		return new ClassValidator(clazz);
	}

}
